#include "hedmodel.h"
#include "solid.h"
#include "face.h"
#include "halfedge.h"
#include "loop.h"
#include "vertex.h"
#include "edge.h"
#include <iostream>


HEDModel::HEDModel()
:firsts(NULL)
{

}


Solid* 
HEDModel::getFirsts()
{
	return firsts;
}


void 
HEDModel::setFirsts( Solid* _firsts)
{
	firsts = _firsts;
}


Solid*
HEDModel::getsolid(int sn)
{
	Solid* s = NULL;
	for(s = firsts; s != NULL; s = s->getNexts())
	{
		if(s->getSolidno() == sn)
			return(s);
	}

	return (NULL);
}


Face* 
HEDModel::fface(Solid* s, int fn)
{
	Face* f = NULL;
	for(f = s->getSfaces(); f != NULL; f = f->getNextf())
	{
		if(f->getFaceno() == fn)
			return (f);
	}
	return (NULL);
}


HalfEdge* 
HEDModel::fhe(Face* f, int vn1, int vn2)
{
	Loop* l = NULL;
	HalfEdge* h = NULL;
	for(l = f->getFloops(); l != NULL; l = l->getNextl())
	{
		h = l->getLedg();
		do
		{
			if((h->getVtx()->getVertexno() == vn1) && (h->getNxt()->getVtx()->getVertexno() == vn2))
			return (h);
		}
		while((h = h->getNxt()) != l->getLedg());
	}
	return (NULL);
}


int 
HEDModel::getNumberOfVertexes()
{
  // counts the number of vertexes in the model
  int numVtxs = 0;
  for(Solid* s = firsts; s != NULL; s = s->getNexts())
  {
    for(Vertex* v = s->getVertex(); v != NULL; v = v->getNextVertex())
    {
      numVtxs++;
    }
  }
  return numVtxs;
}


vector<Vertex*> 
HEDModel::getVertexes()
{
  vector<Vertex*> vtxs;
  for(Solid* s = firsts; s != NULL; s = s->getNexts())
  {
    for(Vertex* v = s->getVertex(); v != NULL; v = v->getNextVertex())
    {
      vtxs.push_back( v );
    }
  }
  return vtxs;
}


vector<Edge*> 
HEDModel::getEdges()
{
  vector<Edge*> edges;
  for(Solid* s = firsts; s != NULL; s = s->getNexts())
  {
    for(Edge* e = s->getEdge(); e != NULL; e = e->getNextEdge())
    {
      edges.push_back( e );
    }
  }
  return edges;
}


void 
HEDModel::getEdgeVertexes()
{
	std::cout << "HEDModel::getEdgeVertexes nao implementado.\n";
}


void 
HEDModel::replaceVertex()
{
	std::cout << "HEDModel::replaceVertex nao implementado.\n";
}


void 
HEDModel::getCurve()
{
	std::cout << "HEDModel::replaceVertex nao implementado.\n";
}
